|
<body>
Enter a Number: <input id="etext" type="text" placeholder="Enter a number here"/>
<input type="button" Value="Print" onclick="PrintStars();" />
<label id="lbl">
</body>
function PrintStars() {
var starcount = document.getElementById("etext").value;
var sx="";
for(x=0;x<starcount;x++)
{
sx +="*";
}
alert(sx);
}
|
|
|
|
|
Thank very much Sumanth. One more little thing i want to ask plz let me know how we can print stars in innerHTML instead of using alert(sx).
as i used document.write(sx).innerHTML;
but this line is replacing input box an button. why is it so?
And Please suggest me some stuff to read for understanding these kind of things as you know i am new to JS.
Again Thank you very much for helping me in this way.
|
|
|
|
|
Hi,
I suggest you to learn some basics of HTML and javascript and DOM; for starters i would say http://www.w3schools.com/ is a good place.
and regarding "document.write" your whole web page will be treated as document so you are replacing your whole html with the result with "write".instead you can add a div to your page
and in the function replace alert with
document.getElementById("result").innerHTML = sx;
But again all this is pretty basic stuff , which you can easily get on web. So its better to search on web and try yourself before posting such small questions on code project.
Happy Coding!!
|
|
|
|
|
Thank you very much for helping dear Sumanth Madireddy.
Now i will try my level best to learn basic stuff form w3school.
Thanks a lot again.
If you don't mind dear can i get your email, because the way you made me understand is quite good and easy for me.
If convenient?
|
|
|
|
|
Hi
I have a menu, and i want when i click on one of item, that item be opened and i can show the sub menu when i click on sub items, and it cloesd if i change the top menu
plz help
more thanks
|
|
|
|
|
How can we help?
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I have C# code dynamically adding a textbox named txtDodic to a data table in the code behind and setting it to a Width of txtDodic.Width = (10 * 4); as so:
tc = BaseControl.CreateTableCell(tr, null, "ColDodic", null);
txtDodic = BaseControl.CreateTextBox(tc.Controls, prefix + "txtDodic", "", "ASPTextBox", "TextBoxDodic");
txtDodic.Attributes.Add("onkeypress", "ValidateDodicInput();");
txtDodic.Width = (10 * 4);
I want to change the Width of the textbox txtDodic to a width of txtDodic.Width = (10 * 16) in a JavaScript function as so:
document.getElementById('" + txtDodic.ClientID + "').Width = (10 * 15);
The problem is that when the JavaScript function is called the width does not change. Please help.
Thanks,
Steve
|
|
|
|
|
You have to use the style attr to set the width
Plus add the ID to the textbox
Now you can use javascript to program the textbox.
txtDocdic.ID = "txtDoctic"
txtDoctic.ClientIDMode = static
txtDocdic.style.add(Htmltextwriterstyle.width, (10 * 4) & "px")
|
|
|
|
|
How do I get the actual txtDocdic to set the ID, static, and style. Do I use var txtDocdic = document.getElementById('" + txtDodic.ClientID + "')? What I did was this:
Script.AppendLine(" txtDocdic.ID = 'txtDoctic'; txtDoctic.ClientIDMode = static; txtDocdic.style.add(Htmltextwriterstyle.width, (10 * 4) & 'px');");
and this did not work.
modified 27-Apr-15 10:41am.
|
|
|
|
|
there should be a property in asp.net called ClientIDMode, you set that to the value needed. Static most likely
Actually when you make a dynamic textbox, its sort of like this in c#
You have to get the server side code right before you fix your javascript.
TextBox txt_firstName = new TextBox();
txt_firstName.ID = "txt_firstName"
txt_firstName.clientIDMode = clientIDmode.static;
txt_firtName.attributes.add("onkeypress", "makeBigger(); return false;";
controls.add(txt_firstName);
Then fix your javascript.
function makeBigger(){
alert('I fired');
var txt = document.getelementbyid('txt_firstName');
txt.style['width'] = '100px';
}
Now look at your HTML source code in your browser, and double check that the ID is correct in the textbox and javascript.
|
|
|
|
|
Dear Sir,
I have a php page and with php way I get the information with below code:
$link = $_SERVER['HTTP_REFERER'];
and but now I want get this information with "document.referrer" and then send to php.
I don't know how i can send this information to php.
Best Regards
|
|
|
|
|
|
I am wrote code in jquery in onBeforeUnlaod event to show broser alert to the user. Here i have situvation to know user clicks on the "Leave the page" button or "Stay on the page" button, based on the button i need to write some code.
Please help me if any of you know about this.
Thansk for your Help.
|
|
|
|
|
Please do not post in multiple places.
Broser conformation alert[^]
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
|
I want to force users to enter dates in a textbox as mm/yyyy
The following works:
<html>
<head>
<title></title>
<script type="text/javascript" >
function testFormat(v) {
//var re = new RegExp("^([1-9]|1[0-2]|0[1-9])/(\d{4})$");
var re = new RegExp(document.getElementById("txtR").value);
if (v.match(re) && (v.length==7)) {alert('ok');} else { alert('oops');}
}
</script>
</head>
<body ><form runat="server" id="Form1">
<input type="text" id="txtR" value="^([1-9]|1[0-2]|0[1-9])/(\d{4})$" style="width:200px;" />
<br />
<input type="text" id="txtA" onblur="testFormat(this.value)" style="width:100px;" />
</form></body>
</html>
However:
- Why does the commented out javascript line not work? Instead I have to use this silly workaround of putting the regular expression in a text field, (well, I can make this hidden) and reference that. It's the only way I can make it work - but it's daft.
- In order to force a 2-digit month, I have added the test for v.length==7 - but it must be possible to amend the regex to check for this? Damned if I can see how...
|
|
|
|
|
Ta - but it still doesn't work. Not sure either how that particular modifier would help anyway?
|
|
|
|
|
Try this:
<script type="text/javascript">
function testFormat(v) {
var re = new RegExp(/^(1[0-2]|0[1-9])[/]{1}([2-9]\d[1-9]\d|[1-9]\d)$/);
if (v.match(re)) { alert('ok'); } else { alert('oops'); }
}
</script>
Should also take care of your "7" problem
modified 18-Apr-15 21:29pm.
|
|
|
|
|
Consider yourself raised to "Hero" status!
IDK how anyone gets their head round regular expressions. I don't pretend to be a genius, but I like to think I'm reasonably intelligent, but regex's defeat me. I'd have more chance solving a Rubik's cube blindfold.
Thank you.
|
|
|
|
|
Hi
umm.. hate to say this, but this doesn't actually work!!!
12/2015 = OK, but
12/1995 = false ??
12/2000 = false ??
any deas..?
|
|
|
|
|
for 12/1995, you see where it says: [2-9] - change it to [1-9]
It was assuming 2000+
12/2000 - just a sec... Let me check it out...
|
|
|
|
|
Ta - that bit works.. For the other - it doesn't seem to like a double-0 ...
|
|
|
|
|
Less restrictive:
<script type="text/javascript">
function testFormat(v) {
var re = new RegExp(/^(1[0-2]|0[1-9])[/]{1}(\d{4})$/);
if (v.match(re)) { alert('ok'); } else { alert('oops'); }
}
</script>
|
|
|
|
|
Thanks ever so
|
|
|
|
|