views:

24

answers:

2

This is code snippet of my html page can i validate the two text feilds specified using jquery ,i am not using any form tag in my html page

<div id="panel1">
<fieldset id="fieldset1"> <legend>Registration Details:</legend>
                Name of business:<br/>
                  <input size="30" type="text" id="businessname"/><br/>
                Keywords :<br>
                  <input size="30" type="text" id="keyword"/><br/>
</feildset>
</div>
+1  A: 

For semantic and valid markup, you do need a <form> tag. No question of its not being there.

Sarfraz
+1  A: 

You can always pick up the fields by their ID, the fact that they are not wrapped in a form makes no difference:

$('#businessname')

It is not valid HTML, however, and you really should use a <form> around form elements.

Why are you not using one?

Oded
Thanks for the reply
mahesh
I extract the values of text boxes using their div id and pass those values to webservices ,i am not using any form tag in my code
mahesh
$('#Addresslisting').click(function() { var businessname = ($("#businessname").val()); var jsonobject = "{\"businessname\":\"" + businessname + "\"}"; $.ajax({ type: "POST", url: "/blockseek30-9-2010/AfterLogin.asmx/SubmitList1", data: jsonobject, contentType: "application/json; charset=utf-8", success: ajaxCallSucceed, dataType: "json", failure: ajaxCallFailed }); });
mahesh
Not using valid HTML can force a browser into "quirk" mode, so even though you don't use it for your app as you use XHR, it is a good idea adding it.If you check the console of Chrome or the interpreted source of for instance IE, you will see that these browsers will move and insert elements to make the content valid, so they can render something they otherwise would not be able to.
Michael
@mahesh - Just wrap a form element around the items, to make sure that your markup is _valid_. Browsers may do strange things with invalid HTML.
Oded