I want to write timestamp generated by java script to a hidden form input field.The following code writes the timestamp to a paragraph(p element) but does not write to the input element.
It writes to one element but fails to do so to another element.
Can anybody throw light on this behaviour of the script?
<!DOCTYPE html>
<html>
<body>
<p id="demo">pkj</p>
<input id="ts" type="time" name="ts"></input>
<script>
var oD = new Date();
document.getElementById("ts").innerHTML = oD.getTime();//**FAILS**
document.getElementById("demo").innerHTML = oD.getTime();//**SUCCEEDS**
</script>
As per your advice I changed the input element's attribute from "innerHTML" to "**
"value" as shown in code below.It is working fine now.
The issue is SOLVED.
thanks
Jayk
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p id="demo" > </p>
<input id="ts" type="time" name="ts" value=""></input>
<script>
var oD = new Date();
document.getElementById("ts").value = oD.getTime();//**SUCCEEDS**
document.getElementById("demo").innerHTML = oD.getTime();//**SUCCEEDS**
var t=document.getElementById("demo").innerHTML
</script>
</body>
</html>
<input> by definition is an empty element, meaning there is no innerHTML, it has no permitted content. And there is no need for a closing tag (</input>).
https://developer.mozilla.org/en/docs/Web/HTML/Element/Input
You can change the property "value", a sort of default input by
document.getElementById("ts").value = oD.getTime();
Or you could add a label like
<label id="label">xyz</label><input id="ts" type="time" name="ts">
and change it with
document.getElementById("label").innerHTML = oD.getTime();
Related
Below is the code. can someone pls help me to identify 3 text boxes individually, without using indexes.
<html>
<head>
<title>test</title>
<script></script>
</head>
<body>
name:
<input type="text"/>
<br/>
name:
<input type="text"/>
<br/>
name:
<input type="text"/>
<div>testdiv</div>
</body>
</html>
You can try below expressions to match each input:
For the first one:
//input[not(preceding-sibling::input)]
For second:
//input[preceding-sibling::input and following-sibling::input]
For third:
//input[not(following-sibling::input)]
I'm trying to get a variable value from a number input without success.
HTML:
<input type="number" min="0" max="5" name="quantity" id="quantity" class="quantity" value="1" />
<div class="selectedvalue"></div>
SCRIPT:
$().ready(function() {
var quantity = $('input[type=number][name=quantity]').val();
$(".selectedvalue").html(quantity);
});
JSFIDDLE
I only can get the attribute value (1)in the number input but not the actual selected value.
Check the example inside W3schools.
In your example, you use the value 1, and always show the value 1, because your set inside the tag.
You does not need jQuery for get this.
The type from your input is number, and add the id from your number for get the value by Id with document.getElementById("yourIdFromInput").value;
<!DOCTYPE html>
<html>
<body>
Number: <input type="number" id="myNumber" value="2">
<p>Click the button to display the number of the number field.</p>
<button onclick="myFunction()">Try it</button>
<p><strong>Note:</strong> input elements with type="number" are not supported in IE 9 and earlier versions.</p>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myNumber").value;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The <p> with innerHTML will show inside html the value with this script.
Reference:
all Explication about that here
Code W3schools.
Question:--
I am using following HTML code showing error message using tool tip whenever length of Textbook equal to zero,
but i couldn't set my defined message inside tool tip.
<body class="claro">
<form action="">
Enter Name:--
<input type="text" name="firstname" data-dojo-props="" data-dojo-type="dijit.form.TextBox"
trim="true" id="firstname" propercase="true">
<button id="button4" data-dojo-type="dijit.form.Button" type="button">Submit
<script type="dojo/method" event="onClick" args="newValue">
alert("Value selected is: "+newValue);
var firstNameId=dijit.byId("firstname").value;
alert('firstNameId.length:----'+firstNameId.length);
if(firstNameId.length==0)
{
var textBox = dijit.byId("firstname");
dijit.showTooltip(
textBox.get("invalidMessage"),
textBox.domNode,
textBox.get("justMessage"),
!textBox.isLeftToRight()
);
}
else
{
alert('wrong');
);
}
<br>
Help me out....
It's been a while since you posted this question, but if you still need it, here's an answer.
Dijit/form/TextBox doesn't have a showTooltip method. To show a tooltip you can instead call something like:
var textBox = dijit.byId("firstname");
textBox.invalidMessage = "Whatever you want";
Tooltip.show(textBox.get("invalidMessage"),
textBox.domNode, textBox.get("tooltipPosition"),
!textBox.isLeftToRight());
Be sure to include dijit/Tooltip!
I cannot get the checkbox selector from the documentation working. Any idea why? $('checkbox').size() is always zero.
HTML page
<html>
<head>
<title>Geb</title>
</head>
<body>
<input type="checkbox" name="pet" value="dogs" checked="true" />
</body>
</html>
Groovy code
Browser.drive {
go "file:///home/zoran/page.html"
println $('checkbox').size() // is always zero
}
To select all checkboxes on a page using a jQuery selector you need to use:
$('input[type=checkbox]').size()
to select all checkboxes use jquery selector as
$('input:checkbox').size()
simply provide id to your checkbox
<input type="checkbox" id="chkPet" name="pet" value="dogs" checked="true" />
and then
$("#chkPet")
I am trying to export a fusion chart created using 'Embedding Charts Using / Tags'.
Export works just perfect with the right click (on the chart) and chose a pdf to export.
But I am not able to make this work via javascript. I have a button outside the chart which upon clicking calls the function below
function myexport()
{
var cObject = getChartFromId('Column3D');
if( cObject.hasRendered() ) cObject.exportChart({exportFormat: 'PDF'});
}
the object above returned is null and this fails on the next line
here is the full prototype
<html>
<head>
<title>My Chart</title>
<script type="text/javascript" src="fusionCharts.debug.js"></script>
<script type="text/javascript" src="fusionChartsExportComponent.js"></script>
<script type="text/javascript">
function ExportMyChart() {
var cObject = getChartFromId('Column3D');
if( cObject.hasRendered() ) cObject.exportChart({exportFormat: 'PDF'});
}
</script>
</head>
<body>
<object width="400" height="400" id="Column3D" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" >
<param name="testname" value="Column3D.swf" />
<param name="FlashVars" value="&dataURL=testData.xml&chartWidth=400&chartHeight=300&DOMId=myChart1®isterWithJS=1&debugMode=0">
<param name="quality" value="high" />
<embed src="Column3D.swf"
flashVars="&dataURL=testData.xml&chartWidth=400&chartHeight=300&DOMId=myChart1®isterWithJS=1&debugMode=0"
width="400" height="300" name="Column3D" quality="high" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
<!-- We also create a DIV to contain the FusionCharts client-side exporter component -->
<div id="holderDiv" align="center">FusionCharts Export Handler Component</div>
<script type="text/javascript">
var myExportComponent = new FusionChartsExportObject("testExporter1", "FCExporter.swf");
//Render the exporter SWF in our DIV fcexpDiv
myExportComponent.Render("holderDiv");
</script>
<input type="button" value="Export My Chart" onclick="ExportMyChart()" />
found the answer for this on fusion charts forum. Looks like there is an issue with the export when both embed and object tag are used in the browser for the chart.
Workaround for this one was explained
here
Please find the modified code below:
My Chart
function ExportMyChart()
{
var cObject = document.getElementById('Column3D');
if( cObject.hasRendered && cObject.hasRendered())
cObject.exportChart({exportFormat: 'PDF'});
}
FusionCharts Export Handler Component
var myExportComponent = new FusionChartsExportObject("fcExporter1", "../../FusionCharts/FCExporter.swf");
myExportComponent.Render("holderDiv");
Hope this helps.