0
<script>
 $(document).ready(function () {
 $("#pid1").click(function () {
 $(this).hide(SpeedEnteredByUser);
 });
});
</script>
<body>
<p id = "pid1">This is paragraph</p>
</body>

I want to call jquery hide function when paragraph is clicked. But I want to pass the speed(i.e. slow/fast) which is entered by the user. How it can be achieved ? Here SpeedEnteredByUser is the value entered by the user(using some form) and I want to pass this value to hide function.

asked Apr 20, 2012 at 9:06
1
  • How does the user select the speed ? is it an input ? or select ? does the user enter a number ? to the words slow / fast etc ? Commented Apr 20, 2012 at 9:13

3 Answers 3

2

Use .val() jQuery method to get the value of a text input (which should hold your speed value!)

$(this).hide(parseInt($("#hide_speed").val(),10));

parseInt() is used to make sure the value of the input is indeed a number. The function accepts 2 arguments, the value itself, and a radix value to validate against (10 means decimal numbers, 2 means binary, 16 means hexa etc).

It's also possible to do with <select>s and other types of inputs.

answered Apr 20, 2012 at 9:09
Sign up to request clarification or add additional context in comments.

Comments

0

fix your ID selector and use value of form element through val() function

 <script>
 $(document).ready(function () {
 $("#pid1").click(function () {
 $(this).hide(parseInt($("#youtextinput").val(),10));
 });
 });
 </script>
 <body>
 <p id = "pid1">This is paragraph</p>
 <input type="text" id="youtextinput"/>
 </body>
answered Apr 20, 2012 at 9:09

Comments

0

Your question is quite vague ... but here goes ... to enable the user to select a speed add this to your HTML :

<select id="UserSelectedSpeed">
 <option value="slow">Slow</option>
 <option value="fast">Fast</option>
</select>

then do the following :

$(document).ready(function () {
 $("#pid1").click(function () {
 $(this).hide($('#UserSelectedSpeed').val());
 });
});

$('#UserSelectedSpeed').val() gets the currently selected value from the select list.

Working example here

answered Apr 20, 2012 at 9:16

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.