Wiping out default text when user will enter a username [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I want to use JavaScript to wipe out default text and allow user to enter a his choice word. How do I integrate this thing with my HTML code. I need it for testing purpose. Below is my HTML code.
<html>
<body bgcolor="black"><form method="get" action ="http://localhost:2013">
<center>
<font color="white" size=65>Enter Word:
<input type="text" name="word"></font></center>
</br><center>
<font color="Green" size=65>
<input type="submit" value="SUBMIT"></font></center><
form>
</body>
</html>
Any suggestions?

<!DOCTYPE html>
<body bgcolor="black"><form method="get" action ="http://localhost:2013">
<center>
<font color="white" size=65>Enter Word:
<input type="text" name="word" placeholder='Default Text'></font></center>
</br><center>
<font color="Green" size=65>
<input type="submit" value="SUBMIT"></font></center><
form>
</body>
</html>
Just add placeholder='Default Text' to your input element.

No need of much items, this will help you...
<form action="demo_form">
<input type="text" name="fname" placeholder="Your default text"><br>
<input type="text" name="lname" placeholder="Your default text"><br>
</form>

Related

Onclick Function when input field requirements are met [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 11 months ago.
Improve this question
I want the submit button's to call the function only if the input fields meet the requirements set. Is there an easier way to do it than making an if statement for each input element?
<div class="container">
<form>
<input id="inputname" type="text" name="name" required placeholder="Your Name">
<input id="email" placeholder="Your E-mail" type="email" name="email" required>
<input id="phone" type="tel" name="phone" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" placeholder="123-456-7890" required>
<textarea type="text" rows="4" placeholder="Add comments(optional)" id="comments"></textarea>
<button type="submit" onclick="submitted()"> Reserve a Table</button>
</form>
</div>
<script>
const container = document.querySelector('.container');
function submitted() {
container.innerHTML = `<i class="fa-regular fa-circle-check"></i><br>
Thank you, the form has been submitted!`
}
</script>
Yes. See this tutorial for more details on form validation.
In particular, under the header Using built-in form validation:
When an element is invalid, the following things are true:
...
If the user tries to send the data, the browser will block the form and display an error message.
See also the note under the constraint validation process to learn more about when this happens.
The originally posted sample is shown this Fiddle but lacked a dot at the start of the container selector.
As a solution here, you can move the function call to the onsubmit handler of the form, instead of the click handler of the submit button. That fiddle is here and includes just the following changed tags: <form onsubmit="submitted()"> and <button type="submit">.

Can someone explain to me this javascript based internal website search script? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Can someone explain to me line by line what is happening in this script ? :
<script type="text/javascript">
function Gsitesearch(curobj){
var domainroot=curobj.domainroot[curobj.domainroot.selectedIndex].value
curobj.q.value="site:"+domainroot+" "+curobj.sitesearch.value
}
</script>
Thanks !
It's from here:
http://www.javascriptkit.com/script/script2/google_site_search2.shtml
The snippet, along with a <form> that submits to http://www.google.com/search, allows you to submit a search to google that limits results to those coming from the domain domainroot.
Full example:
<script type="text/javascript">
// Google Internal Site Search script II- By JavaScriptKit.com (http://www.javascriptkit.com)
// For this and over 400+ free scripts, visit JavaScript Kit- http://www.javascriptkit.com/
// This notice must stay intact for use
function Gsitesearch(curobj){
var domainroot=curobj.domainroot[curobj.domainroot.selectedIndex].value
curobj.q.value="site:"+domainroot+" "+curobj.qfront.value
}
</script>
<form action="http://www.google.com/search" method="get" onSubmit="Gsitesearch(this)">
<p>
<input name="q" type="hidden" />
<input name="qfront" type="text" style="width: 180px" /> <input type="submit" value="Search" /><br />
Search:
<select name="domainroot">
<option value="www.javascriptkit.com" selected="1">JavaScript Kit</option>
<option value="www.dynamicdrive.com">Dynamic Drive</option>
<option value="www.freewarejava.com">FreewareJava.com</option>
</select>
</p>
</form>
<p style="font: normal 11px Arial">This free script provided by<br />
JavaScript Kit</p>

Populate hidden text input using jQuery [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
<input name="input1" id="input1" type="text" value="" class="problem">
<input name="input2" id="input2" type="text" value="" class="hidden">
I'm trying to populate a hidden text input (e.g. input#input2) field with the current value from another text input field (e.g. input#input1) (un-submitted) using jQuery. I've sourced this jsfiddle doing exactly what i require but with a drop down field. And i was wondering if anyone is able to point me in the right direction?
EDIT: Sorry if i wasn't clear, the jsfiddle works perfectly but i'm trying to use a text field instead of a drop down to populate the other field.
i always handle this by storing that value in a variable:
var yourText = document.getElementById("input1").value;
and then just plug it into the hidden field:
$('#input2').val(yourtext);
here's your hidden field:
<input id="input2" type="hidden" />
$("#my_form").submit(function(event){
var visibleInputVal = $("#input1").val();
if(visibleInputVal != ""){
$("#input2").val(visibleInputVal);
}else{
alert("you need to provide a value for input 1");
event.preventDefault();
}
});
<form id="my_form">
<input type="text" value="" id="input1" />
<input type="hidden" value="" id="input2" />
<input type="submit" value="Submit" />
</form>

Make Div enter a search value [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I would like to make this div tag "tile 1" to be selectable and upon clicking it retrieves search results based on a key word.
<div id="tile1" class="live-tile" data-swap="image" data-direction="horizontal" data-stops="80px,90%,100%,90%,0" data-delay="6000">
<div>
<img class="full" src="../bakeware2.png" alt="2" />
</div>
<div>
<img class="full" src="../bakeware3.png" alt="3" />
</div>
</div>
Here is the code that I use for my search bar.
<table align="center">
<tr>
<td align="center"><form action='search.asp' method='post'>
<div style="float:left;">
<input type="search" style="color:#000;" name="keyword" size="30" data-mini="true" value="bakeware">
</div>
<div style="float:left;">
<input type=image src="http://www.kitchenova.com/assets/templates/v32029/images/btn-search.gif" border="0" />
</form></td>
</tr>
</table>
Is there a way I can make the div "tile1" click-able and have it display the results as if I were to type in say "cookies" in the actual search bar itself?
Is this FIDDLE what you're looking for?
JS
$('.clickme').click(function(){
var typeaword = $('#getme').val();
typeaword = '123' + typeaword + 'xyz';
$('.putmehere').html(typeaword);
});

How to prevent user to type into a particular form field? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a form and it has several fields. There is an ID field which is generated from another form. Now i want to prevent users to change that field value.
How do i do this? DO i need any javascript or anything else?
You can use disabled on the field:
<input type='text' disabled />
Or readonly
<input type='text' readonly />
<input type="text" name="NAME-OF-FIELD" value="VALUE-NOT-TO-CHANE" disabled="disabled" />
or you could use
<input type="text" name="NAME-OF-FIELD" value="VALUE-NOT-TO-CHANE" readonly />
or if you need to hide it
< input type="hidden" name="NAME-OF-FIELD" value="VALUE-NOT-TO-CHANE" />
You will still have access to it when you submit the form.
If you can change the HTML, I'd suggest making the input hidden with type="hidden".
If you can't, apply the CSS style display:hidden to it.
Or did you want to leave it visible?
You have to disable the field:
<input type="text" disabled="disabled" />
Or set it readonly
<input type="text" readonly="readonly" />
A readonly element not editable, but gets sent when the form submits. a disabled element isn't editable and isn't sent on submit.Readonly elements can be focused while disabled elements can't.
<input type="text" readonly />

Categories