Question

I want to populate my textbox with value from an element.

Perhaps my code will explain better:

This is in header.ascx

<form method="get" action="/_apps/results.aspx" onsubmit="if(this.elements['query'].value==''){ alert('Enter something.'); this.elements['query'].focus(); return false; } else {  return true; }">
<td width="10%" class="navTopbarText">&nbsp;
<input type="hidden" name="type" id="type" value="banner"> <input type="text" alt="" size="20" maxlength="200" class="formTextboxText" name="query" value=this.elements['query'].value id="query">
</td>
</form>

This part doesn't work: value=this.elements['query'].value What should I replace this by? I would like the value to be what is in the element 'query'.

Thank you all.

Was it helpful?

Solution

I think your markup has several problems but what you ought to do is have an <asp:textbox /> field and define a required field validator for it.

<asp:textbox id="query" runat="server" ></asp:textbox>

<asp:RequiredFieldValidator id="validatorQuery" runat="server" controlToValidate="query" ErrorMessage="Enter Something" />

Then you should remove the whole onsubmit function call from the form

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top