Link to home
Start Free TrialLog in
Avatar of kadin
kadinFlag for United States of America

asked on

I'm new to javaScript. I can't get anything to work.

Nothing is displayed. Is there anything wrong with this code? Thanks. I can never find any success using firebug. I get know errors.

function validate(form) {
      var para = document.createElement("p");
      var star = document.createTextNode("*");
      var sub = document.getElementById("subject-star");
      sub.appendChild(para);
      para.appendChild(star);
      return false
}

<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data" onsubmit="return validate(this);">

<div id='subject-star'></div>

</form>
ASKER CERTIFIED SOLUTION
Avatar of chaitu chaitu
chaitu chaitu
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kadin

ASKER

Thanks for your response.

I'm sorry. It already has a submit button. I forgot to mention that.
now you can  see * in the form.it will be like this .check it in firebug

<div id="subject-star"><p>*</p></div>

Open in new window

Avatar of kadin

ASKER

I don't understand. Are you saying add this to the form:
<div id="subject-star"><p>*</p></div>

I did. It doesn't display on the web page and firebug errors show nothing as always.
when you click submit button then above code will be appended to div tag dynamically so you can see * in the form.
Avatar of kadin

ASKER

Yes I know. But it's not working. If you don't see anything wrong with the code, could there be something else? I am using firefox. I tested it in safari too, but it don't work there either.
Avatar of kadin

ASKER

I just noticed if I put this in the form and disable javascript, the form does not display the star. Even when I clear recent history and refresh the browser.

<div id="subject-star">*</div>
Avatar of kadin

ASKER

Just a sec. My css has a problem.
Avatar of kadin

ASKER

That was it. In all the test I've been running today I forgot to delete display:none; in css for id subject-star.

Thanks for helping me come to those thoughts that led me to remember this.