I need the following change using javascript:
from:
<input id="innn" value="" />
to:
<input id="innn" value="SOME_VALUE" />
I tried this:
document.getElementById("innn").setAttribute("value", "189");
and this:
document.getElementById('innn').value = '152';
it worked but it changed only visual on page not the html code and i need to change the code as shown below:
<input id="innn" value="" /> --> <input id="innn" value="125" /> --><input id="innn" value="158" />
Please help or I must use php like : <input id="innn" value="<? php ... ?>" /> ????
HTML is what is rendered in order for your browser to know what to show on your page. Once sent by the server it will not change (at least not with basic JavaScript). There are more advanced ways of doing things, but they are not simple. When you call a JavaScript function to change something, it changes it in the DOM, so you will see the change on your screen, but when you click view-source your browser is fetching the original page again from the server to show you. In some browsers they have something called Inspect mode which allows you to see what the HTML looks like right now for your page. In that case it will show the updated code. If you want that when someone clicks view-source and sees SOME_VALUE in the value for id="innn", then you would need to use PHP.
document.getElementById("innn").value = somevalue
Related
I am trying to repair an existing web form that submits a text area's contents to an external site's shopping cart service. The textarea is named "adtext" and upon submission it runs a few different scripts to calculate pricing, etc. It ultimately re-writes the ad content into a value named op31 (which is recognized by the shopping cart). The cart system recently got updated and it broke our script to convert line breaks in this text area into something that would be retained in that other site. I've tried looking at other sites, but it's over my head. I'm not particularly good at this stuff. I'm sure this isn't, and likely wasn't the best way to do it. I've seen CSS suggestions but don't understand it enough to actually implement them.
I've stripped out as much code as I comfortably could to clean it up, but still retain the issue. I'm wondering if someone could assist me with updating this function into something that would convert the "adtext" textarea's line breaks into something usable when written to "op31".
<script language="JavaScript" type="text/JavaScript">
function ConvertCarriageReturns(textarea, strReplace){
document.form.op31.value = escape(textarea.value)
for(i=0;i<document.form.op31.value.length;i++){
if(document.form.op31.value.indexOf("%0D%0A") > -1 ){
document.form.op31.value = document.form.op31.value.replace("%0D%0A",strReplace)
}
}
document.form.op31.value = unescape(document.form.op31.value)}
</script>
<form
action="https://(cart's url)/addtocart.aspx"
method="post"
name="form">
<textarea name="adtext" rows="12"></textarea>
<input alt="Add To Cart" name="add"
onclick="ConvertCarriageReturns(this.form.adtext,'<br>');
return checkwords(this)" src="https://....Add-To-Cart.gif"
type="image" />
<input name="item" type="hidden" value="(misc cart parameters" />
<input name="op31" readonly="readonly" type="hidden" />
</form>
You can use this native PHP function called nl2br
Like this:
$text = nl2br(this.form.adtext);
So let's say I have a form tag like so. And I want to print the contents of the file to screen using JavaScript. How do I go about doing that?
<form action="/missions/basic/3/index.php" method="post">
<input type="hidden" name="file" value="file.php" />
<input type="password" name="password" />
<br />
<br />
<input type="submit" value="submit" />
</form>
What I want is to use the alert() function to show the contents of file.php, even though the contents are hidden.
What I want is to use the alert() function to show the contents of file.php, even though the contents are hidden.
You just can't. Don't waste your time :)
If your web server is configured correctly it will never output PHP code even if you could request that from JavaScript.
You can grab and show the output of a PHP file on the client but not its source code like that, unless there is a mess up or it is by design.
PHP is server side programming. When you run, it'll return the output of server coding not the server code
I've created a search page that can be toggled between french and english. So when the user searches a record and toggles to french it displays the same record they were viewing on the english page.
What I want to do is display the record name in the search box when the page is toggled.I assumed it was as simple as doing a $('#inputID').val(record); but it doesn't seem to be working. I've alerted the record name and it works fine, so I'm stumped. All the scripts are linked correctly as well so that's not the problem.
Autocomplete Box Code
<div id="ui-widgit">
<label for="searchParams">
<h1>Search All Programs (By Screen Number or By Error Code):</h1>
</label>
<input type="text" id="inputID" name="inputID" value="" class="ipt_Design" style="width:255px;" />
<input type="button" value="Search" name="searchBtn" class="btn_Design" onclick="showSearch(inputID.value)"/>
</div>
Try to change the value of inputID with this
$('#inputID').val(recordToggle);
also have tried this:
$('#inputID input').val(recordToggle);
It is hard to tell with your presented markup but I am assuming you are trying to change the value of $('#inputID') after the page refreshed. It is important where you put this code. If it is placed before <input type="text" id="inputID" name="inputID" value="" class="ipt_Design" style="width:255px;" /> you will not return anything with $('#inputID') so you will change the value of nothing to your text. It will give no error. To fix this you can use:
$( document ).ready(function(){
$('#inputID').val(recordToggle);
});
Be sure to read about jQuery's ready function because load may be the better choice.
If this doesn't fix your problem let me know. I will update my answer.
I'm jQuery beginner.
I'm trying to modify the source code of a page I'm browsing, using Firefox plus Greasemonkey.
How can I modify:
<input id="HiddenCategory" type="hidden" name="PageCategory"></input>
to:
<input id="HiddenCategory" type="text" name="PageCategory" value="OTHER"></input>
?
Something like this?
$("#HiddenCategory").attr("type", "text").val("OTHER");
This is untested but i think it should work ok.
I have an issue I need to fix on an existing app that I didn't initially write. Here is a snippet of code that doesn't do what it is intended to do. What it is supposed to do is take the value of the field and upon clicking "Search", append that to the redirection to pass in the querystring to the destination page:
<form name="frm_someform">
<input type="text" name="f_date" id="f_date"/>
<input type="button" value="Search" onclick="parent.location='runreport.asp?date=' + document.frm_someform.elements['f_date'].value); + '"/>
</form>
Now, as you javascript folks can plainly see, the concatenation doesn't work. I've searched high and low for how to properly concatenate, but something isn't translating correctly (in my head). Note that if I take out the concatenation, the redirection works fine, so there is something with that causing the issue. Yes, of course in the example above, I could simply make the form submit the proper value with a real 'submit' button, but I have whittled the code down here for simplicity - it is much more complex than the example I have above.
(*Note, I successfully tested concatenation through other javascript functions, but the possibility exists that the purely inline code must be different)
Thanks in advance,
Beems
Please, try this:
<form name="frm_someform">
<input type="text" name="f_date" id="f_date"/>
<input type="button" value="Search" onclick="parent.location='runreport.asp?date='+ document.getElementById('f_date').value"/>
</form>