Jump to content

getElementById for input box


eevan79

Recommended Posts

I am using dropdown box to select years and with submit button get ajax request for selected years. Following code is not working (works when page reload and server request method is post):

 

<input type='button' class='inputButton' onclick='requestActivities2(\"includes/get_monthly.php?year=\"+document.getElementById(\"yearsid\").value\"+&month=$month\");'  value='$lang[submit]' name='Submit' />

 

And select:

<select id='yearsid' name='years'>

 

How to getElementById for Ajax request with button (not submit)?

Link to comment
https://forums.phpfreaks.com/topic/214453-getelementbyid-for-input-box/
Share on other sites

I don't know about anything else all i can tell you is that you have conflicting "" and '' in your first line i think :/.

 

Also try.

onsubmit = "return false"

This will stop it from submitting ,and therefor, act like a button. The onclick will still do what it's supposed to do.

Not sure I understand what you're asking..? You can return the element object for a button input just like a submit input?

 

If I choose 2010 from dropdown (select) I want to get that value for Ajax request without page refreshing. So atribute onclick will be:

 

onclick='requestActivities2("includes/get_monthly.php?year=2010");'

 

requestActivities2 is Ajax script to get request from specified url.

Is this possible?

It won't work. Here is all code:

<form name='myform' method='post' action=''>

<select id='yearID' name='years'>
<option  value='2010'>2010</option>
<option  value='2009'>2009</option>
<option  value='2008'>2008</option>
</select>

<input type='button' onclick='requestActivities2("includes/get_monthly.php?year="+this.value);'  value='Submit' />

</form>

 

EDIT:

Solved:

onclick='requestActivities2("includes/get_monthly.php?year="+yearID.value); :D

Ah sorry. Okay give this a try..

 

<form name='myform' method='post' action=''>

<select id='yearID' name='years'>
<option  value='2010'>2010</option>
<option  value='2009'>2009</option>
<option  value='2008'>2008</option>
</select>

<input type='button' onclick='requestActivities2("includes/get_monthly.php?year="+document.getElementById("yearID").value);'  value='Submit' />

</form>

 

I'd definitely recommend moving such logic to a function though.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.