1

I'm new at JavaScript and I need some help to submit my form when anyone select anything from the dropdown list. Here is the sample code :

<form action="" method="post">
  <select name="car" onChange="this.form.submit()">
    <option value="car1">car1</option>
    <option value="car1">car1</option>
    <option value="car1">car1</option>
  </select>
  <!-- Some other code -->
  <input type="submit" name="sentvalue">
</form>

This is my form and when anyone selects the dropdown, the form automatic submit but I also need the sentvalue when automatic submit the form. So can anyone help me to capture the sentvalue when anyone select the dropdown.

2
  • 2
    I think when the form is submited. the value of select box <code>car</code> will be sent belong to request. dont worry about that Commented Jul 22, 2013 at 3:57
  • Yeah i got the value car but i also need the value of submit button. So i posted the question. If you can please help me. Commented Jul 22, 2013 at 4:20

4 Answers 4

1

If you want to send any other data with the form submit you can send it in hidden inputs

<input type='hidden' name='data1' value='Test1' />
<input type='hidden' name='data2' value='Test2' />
//etc

And if you want the value of submit button with the form just set the value attribute into your code for submit button every this else seems fine,

<input type="submit" name="sentvalue" value="Test1" />

Hope this answers your question

Sign up to request clarification or add additional context in comments.

1 Comment

i think i got my answer. value was not set there. Thanks mate
1

Just give the <input> tag a name

<input name="submitbtn" type="submit" value="sentvalue" /> 

then you can get it by $_POST['submitbtn'] in case of PHP which value is "sentValue"

1 Comment

You've two name tags? the second name tag should be a value?
0

It sounds like you want the value of the input field (sentvalue) to be submitted as well. But how do you guarantee that the value was specified by the user? Is this supposed to be a hidden input field?

Either way your input tag is incomplete. This sounds better:

<input type="text" name="sentvalue"></input>

Also, when you submit, the value of this field (sentvalue) will be passed in too. As long as your tags are right you don't need to worry.

1 Comment

why not <input type="text" name="sentvalue" /> ?
0

You will have to create a hidden input element

<input type='hidden' id='sentvalue' value='' />

and call a function on submit instead of directly submitting Use this in the function to set the values and submit

var e = document.getElementByName("car");
document.getElementById("sentvalue").value = e.options[e.selectedIndex].value;
this.form.submit();

1 Comment

never use ` as a quotes in here, it is being used for formatting the code.

Your Answer

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.