Guest ashwinkudwa Posted January 12, 2006 Share Posted January 12, 2006 Does anybody know as to how can i preselect the topmost radio button among the many dynamically generated radio buttons when the page loads with the help of html:radio tag. Link to comment Share on other sites More sharing options...
aspnetguy Posted January 12, 2006 Share Posted January 12, 2006 if they are dynamically generated through a for loop or some thing do this for(i=0;i<10;i++){ if(i==0) { radioHtml = "<input type=radio selected>"; } else { radioHtml = "<input type=radio>"; } Response.Write(radioHtml);} Link to comment Share on other sites More sharing options...
Jack McKalling Posted January 17, 2006 Share Posted January 17, 2006 (edited) And if you like to write in newer HTML, called Xhtml, and for the difference execute JavaScript instead of VBScript, you could do it like this: for (i=0; i<10; i++){ if (i==0) { radioHtml = '<input type="radio" selected="selected">'; } else { radioHtml = '<input type="radio">'; } document.write(radioHtml);}:)Oh, and before I forget, you can comprimate all this to just thes lines:for (i=0; i<10; i++){ radioHtml = '<input type="radio"' . ( (i ==0) ?' selected="selected"' :'' ) . ' />';} document.write(radioHtml); Edited January 17, 2006 by Dan The Prof Link to comment Share on other sites More sharing options...
niche Posted July 14, 2011 Share Posted July 14, 2011 I found that the attribute "checked" worked for me as in : <input type="radio" name="upc" value="upc" checked /> Include UPC<br /> Link to comment Share on other sites More sharing options...
thescientist Posted July 14, 2011 Share Posted July 14, 2011 you mean checked="checked"? I believe that is the proper way of implementing it. Link to comment Share on other sites More sharing options...
Ingolme Posted July 14, 2011 Share Posted July 14, 2011 This thread is five years old! Let it rest. Link to comment Share on other sites More sharing options...
thescientist Posted July 14, 2011 Share Posted July 14, 2011 whoa! >.<I guess that's what you get for just selecting the read last post orange box, haha. Link to comment Share on other sites More sharing options...
niche Posted July 14, 2011 Share Posted July 14, 2011 (edited) thescientist, good point on the checked="checked". I'm sure you just helped me avoid a validation issue. Anyway, I was just trying to make use of the archive. Interestingly, it was the only topic that came back on my search. I expected more topics on the subject. Edited July 14, 2011 by niche Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now