Reputation: 171
I have a popup that prompts the user to make a selection from dropdown menu or if is not in the DB there is a textbox for user to enter a number.
I would like to grab the value of whatever the user picked to do i.e. either choice (1 of the 2 not both) and do something with the value. My problem is how to do that in javascript or jquery.
Here is my html/php code
<table>
<tr>
<td class='Fnumber'> <span><?php xl('Send to', 'e'); ?>:</span></td>
</tr>
<tr>
<td>
<select id='numberinfo' name='send_to'>
<?php
echo "<option value='' selected='selected'>Select Number Destination</option>";
foreach($send_to as $key => $value) {
echo " <option value='$value' ";
echo ">$value </option>\n";
}
?>
</select>
</td>
</tr>
<tr>
<td class='Fnumber'><span><?php echo "OR" ?></span></td>
</tr>
<tr>
<td class='Fnumber'><span><?php xl('Enter Your Number', e); ?>:</span></td><br/>
<tr>
<td class='Fnumber'>
<input type="text" class="clearable" name="send_to" placeholder="Enter Your Number" maxlength="10" onkeypress="return isNumberKey(event)"/>
</td>
</tr>
</table>
Upvotes: 0
Views: 765
Reputation: 1308
will this logic do? Assume
<select id='numberinfo' name='send_to'>
<option value='initialvalue' selected="selected">Select One</option>
<option value='value1'>Select One</option>
<option value='value2'>Select One</option>
</select>
<input id="inputtext" type="text" placeholder="Input Number"/>
and javascript
var finalvalue = "";
if ($("#numberinfo").val() == 'initialvalue') {
if ($("#inputtext").val().length > 0) {
finalvalue = $("#inputtext").val();
}
} else {
finalvalue = $("#numberinfo").val();
}
if (finalvalue.length == 0) {
alert("Please input one of two")
} else {
alert("Inputed: " + finalvalue)
}
you can check wether the input changed or not
How do I know that a form input has changed?
http://www.thoughtdelimited.org/dirtyFields/examples.cfm
or use predefined value
Upvotes: 1