views:

175

answers:

2

Hi.

I'm trying to preset the value of a dropdown menu and the value of a text box in an HTML form. As soon as the user taps the button in my iPhone app, it enters the webview and I was hoping to preset one of the dropdown menus and text field.

How do I go about this?

I want to set the dropdown to value "4" and the text field to "Giro Apps"

Here's the relevant HTML form code:

<select id="advSrcId" class="list" onchange="showOther($('advSrcId').options[$('advSrcId').selectedIndex].value)" name="advSrcId">
<option selected="" value="">Select</option>
<option value="1">Google</option>
<option value="2">Facebook</option>
<option value="3">Friend Referral</option>
<option value="4">Other</option>
</select>
<div id="otherAdvsrc" style="">
<p>
Please give details here:
<br/>
<input class="text" type="text" value="" name="advsrc"/>
<br/>
</p>
</div>

TIA!

+1  A: 

You are currently selecting the blank value in your select. Change these two options:

<option value="">Select</option>
<option selected="selected" value="4">Other</option>

Or even better remove the blank option and only change the 4 option.

For your input add the initial text as the value of the value attribute:

<input class="text" type="text" value="Giro Apps" name="advsrc"/>
Robert Menteer
I'm actually not trying to change it via HTML. I need to set the code via XCode.I'm making an iPhone app, and there's a button, which, when tapped, will show a webview of an HTML form. When the webview loads, I need the values of the dropdown and the text below it to be preset to the values above. Can't touch the backend HTML of the site, so I'll have to include it in the app's code. :)
laura
+1  A: 

Check out the documentation for -[UIWebView stringByEvaluatingJavaScriptFromString:]. The javascript you pass in can modify the DOM of the page being displayed.

It looks like you have JQuery available, so the script might be as simple as:

$('input[name=advsrc]').text('Giro Apps')
$('option[value=4]').attr('selected','selected')

Just make sure you wait for the webViewDidFinishLoad: message to hit your delegate before you do this.

Tom