We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,991 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Use Javascript varible value

here is one form element.

<input value="-7" class="validate[required,custom[integer],min[5]] text-input" type="text" name="min" id="min" />

here is one more problem..
i wanto use my javascript varible value in above class "validate[required,custom[integer],min[5]]" here like use dynamic number where 5 is using how to do it?
Regards..

2
Contributors
1
Reply
3 Hours
Discussion Span
3 Months Ago
Last Updated
2
Views
Farhad.idrees
Junior Poster
102 posts since Dec 2010
Reputation Points: 11
Solved Threads: 0
Skill Endorsements: 0

You cannot insert JavaScript right in the middle of a HTML element property, but you could access an element property to assign a value to the property. Once the element is created and added to the DOM, you then can use JavaScript to do the work. When I sad "created and added," it means when the page is loaded and/or ready. A simple way (but not very pretty) is to add JavaScript at the end of the body tag to run the modificaton. Or you could use onload in body tag to run your function once done.

<html>
<head>
  <style type="text/css">
  input.initclass {
    /* whatever initial style or leave it empty if none */
  }
  </style>
  <script type="text/javascript">
  var validate = ["class1", "class2", "class3", "class4"];
  function changeInputClasses() {
    var el = document.getElementById("min");
    // change the element property of class from "initclass" to "class4"
    if (el) { el.className = validate[3]; }
  }
  </script>
</head>

<body onload="changeInputClasses()">
 ...
 <input value="-7" class="initclass" type="text" name="min" id="min" />
 ...
 ...
</body>
</html>
Taywin
Posting Maven
2,633 posts since Apr 2010
Reputation Points: 275
Solved Threads: 375
Skill Endorsements: 17

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0577 seconds using 2.69MB