Modifying the value of text input with js/ jquery
Topics related to client-side programming language.
Post questions and answers about JavaScript, Ajax, or jQuery codes and scripts.
-
Marius
- Posts: 107
Modifying the value of text input with js/ jquery
How can I dynamically set /modify the values of certain form elements, more specifically certain input text fields? So far, whenever I load my html page, I am just getting the blank input field, but I want to add it the value of 1.
Here is an example of how I am trying to do this.
Code: Select all
<!doctype html>
<html>
<head>
<script type="text/javascript" src="javascript/jquery-1.6.1.min.js"></script>
</head>
<body>
<form id="form1">
<input type="text" name="q01" maxlength="1" />
</form>
<script type="text/javascript">
// here what JS /jQuery code so to set /modify value of #q01 ?
</script>
</body>
</html>
The reason this needs to be done dynamically is because the value of form could be different every time.
MarPlo
Posts: 186
Hi,
Add an ID to the input text field, for example:
Code: Select all
<form id="form1">
<input type="text" name="q01" id="id_i1" maxlength="1" />
</form>
And the code.
- With pure JavaScript:
Code: Select all
<script>
document.getElementById('id_i1').value = 'The value';
</script>
- With jQuery:
Code: Select all
<script>
$('#id_i1').val('The value');
</script>
Similar Topics
-
Link inline with the text
HTML - CSS
First post
Hi members I'm looking for the script for a link <href> to another URL.
I give part of my text and the link as it is now on my page:
and...
Last post
Hello,
In your case, put both the text and the link inside the <p> tag.
<p>and there where useful, supplemented with comments, tips...
-
Speech to text without https
General Forum
First post
Pleasant Coursesweb,
Is their anything posible without https for speech to text fill-in ?
Or must I turn my SSL document on the XAMPP-server ?
Last post
Hello,
I don't know about speech to text fill-in.
Anyway, I want to inform you that this forum will be closed for register or posting.
Any...