I've been grappling with this issue for a while now and I can't seem to make any progress. As someone who isn't well-versed in JavaScript, I've scoured various forums and websites for a solution but to no avail.
My current challenge involves populating a form using a webView in xCode.
The form is located on the website .
This is the markup of the form on the website:
<form name="data[Search][form]" METHOD="post" ACTION="/search/advanced/find" ID="frmAS" >
<ul>
<li><input type="hidden" name="device" id="device" value="mobile" title="mobile">
<input type="hidden" name="iframe" id="iframe" value="11" title="mobile" > Keyword: </li>
<li><input type="text" name="data[Search][keyword]" id="SearchKeyword" title="search by keywords" />
<input ID="SearchSubmit" class="BTNsend" type="submit" value="Find" name="data[Search][submit]"/></li>
<li>Zip / Postal Code:</li>
<li><input type="text" title="Zip search" value="" name="data[Search][zip_code]" /> <input ID="SearchSubmit" class="BTNsend" type="submit" value="Find" name="data[Search][submit]"/> </li>
<li><select name="data[Search][distance]" style="font-size:120%; ">
<option value="1">1</option>
<option value="5" selected="">5</option>
<option value="10">10</option>
<optionvalue="20">20</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="200">200</option>
</select> <input type="radio" ID="SearchDistanceUnit" value="Mi" checked="" name="data[Search][distance_unit]" class="BTNradio"/> Mi
Specifically, I am attempting to modify the text field with the title "zip search" and submit the form programmatically. However, my code doesn't seem to be working as expected - it doesn't even populate the text field.
NSString* javaScriptString = @"document.getElementById('data[Search][zip_code]').elements.value='22911';";
[self.webView stringByEvaluatingJavaScriptFromString: javaScriptString];
Unfortunately, my attempts are futile. I have also experimented with GetElementsByName and various other methods without success.