开发者

Preset value of HTML Forms

开发者 https://www.devze.com 2022-12-24 11:46 出处:网络
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 o

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>
    <opt开发者_如何学JAVAion 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!


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"/>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号