Re: accessing dynamic generated dom element with javascript in IE
"Michel Carroll" <[email protected]>
| Newsgroups | gmane.comp.web.dom.wdf |
|---|---|
| Message-ID | <[email protected]> |
Neither browser knows what myform is. (Firefox complains in the
javascript console).
I fixed this by putting in a line that went:
var myform=document.forms[0]
but ran into problems with the line:
document.myform.counter.value = counter;
what is document.myform.counter?
btw, the page does some cool stuff:-)
Michel
--- In [email protected], "Habib, Fatma" <ms_f_habib@y...> wrote:
>
> it didn't work. it compares q with myform.elements["Q_" + i] and q
is not defined.
>
> in the if, I assign a value to q then test if it is true .
> The problem is that I have a remove question button, then not all
questions from 1 to counter are defined
> here are the important parts of the code
> Thanks,
> F. Habib
>
> code:
> javascript:
>
>
> var counter = 0;
>
> function moreFields()
> {
> counter++;
> var newFields =
document.getElementById('readroot').cloneNode(true);
> newFields.id = '';
> newFields.style.display = 'block';
> var newField = newFields.childNodes;
> for (var i=0;i<newField.length;i++)
> {
> var theName = newField[i].name
> if (theName)
>
>
> newField[i].name = theName + counter;
>
> }
> var insertHere = document.getElementById('writeroot');
> insertHere.parentNode.insertBefore(newFields,insertHere);
> }
>
> function valid()
> {
>
> var str="";
>
>
> for (i=1 ; i<= counter ; i++)
> {
>
>
> if ((q = myform.elements["Q_" + i]))
> {
>
> if ( q.value == "")
> {
> str = str + 'enter a question plz';
> }
> c1 = myform.elements["C1_" + i];
> c2 = myform.elements["C2_" + i];
> c3 = myform.elements["C3_" + i];
> c4 = myform.elements["C4_" + i];
> c5 = myform.elements["C5_" + i];
> c6 = myform.elements["C6_" + i];
> a = myform.elements["A_" + i];
> m = myform.elements["M_" + i];
>
> cc = 0;
>
> if (c1.value!="")
> {
> cc ++;
> }
>
> if (c2.value !="")
> {
> cc ++;
> }
> if (c3.value!="")
> {
> cc ++;
> }
>
> if (c4.value !="")
> {
> cc ++;
> }
> if (c5.value!="")
> {
> cc ++;
> }
>
> if (c6.value !="")
> {
> cc ++;
> }
> if (cc<=1)
> {
> str = str + ' u must fill at least 2 choices';
> }
>
> if (a.value =="")
> {
> str = str + ' u must select an answer';
> }
>
> if (a.value!="")
> {
> x=a.value
>
> ca = myform.elements["C" + x + "_" + i];
> if (ca.value=="")
> {
> str = str + ' answer must not be null';
> }
>
> }
> if (m.value <= 0)
> {
> str = str + ' mark must be >0';
> }
>
>
> }
>
> }
>
> if (str!="")
> {
>
> alert (str);
> return false;
>
> }
> else
> {
> document.myform.counter.value = counter;
> return true;
>
> }
> }
>
> html
>
> <div id="readroot" style="display: none">
> <p class="hr"> </p>
>
> <input type="button" value="Remove Question" style="font-size:
10px"
> onClick="
> this.parentNode.parentNode.removeChild
>
> (this.parentNode);
> "><br><br>
>
> <textarea name="Q_" rows=3 cols=40>Enter Question</textarea>
> <br/><br/>
> <input type =text width=35 name="C1_" value="choice1" />
> <br/><br/>
> <input type =text width=35 name="C2_" value="choice2" />
>
> <br/><br/>
> <input type =text width=35 name="C3_" value="choice3" />
> <br/><br/>
> <input type =text width=35 name="C4_" value="choice4" />
>
> <br/><br/>
> <input type =text width=35 name="C5_" value="choice5" />
>
> <br/><br/>
> <input type =text width=35 name="C6_" value="choice6" />
> <br/><br/>
>
>
> <select name="A_">
> <option value=""></option>
> <option value="1">1</option>
> <option value="2">2</option>
> <option value="3">3</option>
> <option value="4">4</option>
> <option value="5">5</option>
> <option value="6">6</option>
> </select>
>
> <input type = "text" size="2" name="M_" />
> <br><br>
>
> </div>
>
> <form action= someaction.php onsubmit="return valid()" method=post>
>
> <span id="writeroot"></span>
> <input type="button" value="Add Question" onClick="moreFields()">
> <input type=submit>
> </form>
>
>
> "John M. Hann" <john.hann@e...> wrote: Hi Sleeping Beauty,
>
> Change
>
> if ((q = myform.elements["Q_" + i]))
>
> to
>
> if ((q == myform.elements["Q_" + i]))
>
> Note: double-equal ("==")
>
> -- John
>
> http://e-numera.com/
>
> --- In [email protected], "Sleeping Beauty"
<ms_f_habib@y...> wrote:
> >
> > I a creating a site for entering tests
> > the instuctor can add questions whenever he needs and the
question and
> > answer fields are appended with the questions counter
> >
> > I've created a javascript function to validate the questions
> > the problem is that it doesn't work in IE it worked in firefox
> >
> > this is how I access the fields
> > for (i=1 ; i<= counter ; i++)
> > {
> > if ((q = myform.elements["Q_" + i]))
> > {
> >
> > if ( q.value == "")
> > {
> > str = str + 'enter a question plz'
> > }
> > }
> >
> > }
> > in IE q is considered undefined!
> >
> > is there any other option, coz I need the code to work in IE
> > thank you
> > aurora
> >
>
>
>
> [Non-text portions of this message have been removed]
>
>
>
> Unsubscribe
> [email protected]
>
> List info
> http://www.quirksmode.org/dom/list.html
>
>
>
> SPONSORED LINKS
> Dom perignon
Dom pedro lisboa
Javascript dropdown menu
Javascript
Dom henrique hotel
Dom pedro hotel
>
> ---------------------------------
> YAHOO! GROUPS LINKS
>
>
> Visit your group "wdf-dom" on the web.
>
> To unsubscribe from this group, send an email to:
> [email protected]
>
> Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service.
>
>
> ---------------------------------
>
>
>
>
>
>
> <html>
> <a
href="Get'>http://www.spreadfirefox.com/?q=affiliates&id=97679&t=1">Get
Firefox!</a>
>
> <a
href="http://www.spreadfirefox.com/?q=affiliates&id=97679&t=61"><img
border="0" alt="Get Firefox!" title="Get Firefox!"
src="http://sfx-images.mozilla.org/affiliates/Buttons/110x32/trust.gif"/></a>
>
> </html>
>
>
>
>
>
>
>
>
>
> ---------------------------------
> Yahoo! Shopping
> Find Great Deals on Holiday Gifts at Yahoo! Shopping
>
> [Non-text portions of this message have been removed]
>
------------------------ Yahoo! Groups Sponsor --------------------~-->
Get fast access to your favorite Yahoo! Groups. Make Yahoo! your home page
http://us.click.yahoo.com/dpRU5A/wUILAA/yQLSAA/9rHolB/TM
--------------------------------------------------------------------~->
Unsubscribe
[email protected]
List info
http://www.quirksmode.org/dom/list.html
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/wdf-dom/
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/