Jump to content

[SOLVED] Display Doesn't Work With JS...


The Little Guy

Recommended Posts

I don't under stand why this displays properly:

 

<div style="vertical-align:top;max-width:100px;border:solid 1px #AAA;border-right:0;padding:5px;font-size:18px;display:table-cell;font-weight:bolder;">Ryan</div>
<div style="vertical-align:top;padding:5px;border:solid 1px #AAA;border-left:0;display:table-cell;width:200px;">
<input type="text" id="setStatus" rows="1" style="font-family:verdana, arial, times;border:0;outline:none;font-size:18px;color:#AAA;" class="bold" />
</div>

 

But when I turn it into JavaScript like this:

function setStatus(id,first){
var status = document.getElementById(id);
var stat = '';
stat += '<div style="vertical-align:top;max-width:100px;border:solid 1px #AAA;border-right:0;padding:5px;font-size:18px;display:table-cell;font-weight:bolder;">'+first+'</div>';
stat += '<div style="vertical-align:top;padding:5px;border:solid 1px #AAA;border-left:0;display:table-cell;width:200px;">';
stat += '<input type="text" id="setStatus" rows="1" style="font-family:verdana, arial, times;border:0;outline:none;font-size:18px;color:#AAA;" class="bold" />';
stat += '</div>';
status.innerHTML = stat;
document.getElementById('setStatus').focus();
}

 

The display is completely wrong! basically the table element doesn't work...

Link to comment
Share on other sites

Works fine for me in both IE and FF. However, they both display very differently in thos two browsers - you'll need to work on the CSS to get them to display consistently.

 

My guess is that you are not passing an ID to the function for an element on the page or one that does not support innerHTML.

 

Here is what I used to test.

<html>
<head>
<script type="text/javascript">

function setStatus(id,first){
var status = document.getElementById(id);
var stat = '';
stat += '<div style="vertical-align:top;max-width:100px;border:solid 1px #AAA;border-right:0;padding:5px;font-size:18px;display:table-cell;font-weight:bolder;">'+first+'</div>';
stat += '<div style="vertical-align:top;padding:5px;border:solid 1px #AAA;border-left:0;display:table-cell;width:200px;">';
stat += '<input type="text" id="setStatus" rows="1" style="font-family:verdana, arial, times;border:0;outline:none;font-size:18px;color:#AAA;" class="bold" />';
stat += '</div>';
status.innerHTML = stat;
document.getElementById('setStatus').focus();
}

</script>
</head>

<body>
<h3>Hard coded HTML:</h3><br>
<div style="vertical-align:top;max-width:100px;border:solid 1px #AAA;border-right:0;padding:5px;font-size:18px;display:table-cell;font-weight:bolder;">Ryan</div>
<div style="vertical-align:top;padding:5px;border:solid 1px #AAA;border-left:0;display:table-cell;width:200px;">
<input type="text" id="setStatus" rows="1" style="font-family:verdana, arial, times;border:0;outline:none;font-size:18px;color:#AAA;" class="bold" />
</div>

<br><br>

<h3>Dynamically generated from JS (span with the id of 'test'):</h3><br>
<span id="test"></span>
<br>
<button onclick="setStatus('test', 'Ryan')">Run setStatus('test', 'Ryan')</button>


</body>
</html>

Link to comment
Share on other sites

Well... Here is the code to activate the function, it is in the "a" tag...

 

<?php
echo '
<div class="content">';
	//include 'inc/profileNav.php';
	//$sql = mysql_query("SELECT * FROM ");
	echo '<div class="fontbig block" id="status">
	<a href="javascript:void(0);" onclick="setStatus(parentNode.id,\''.$_SESSION['user']['first'].'\');">Whats going on?</a>
	</div>
</div>';
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.