/    Sign up×
Community /Pin to ProfileBookmark

Ajax: Creating new table .width help needed

I’m an experienced Ajax programmer using PHP but I’m having trouble understanding why this ajax code isn’t working. The thing that is different about this ajax code is that I am creating a table on a form that did not exist when the form was first loaded.

I have a php form. When I click on a link I want a table to be displayed with a width of 850, done using Ajax.

I can create the table fine using ajax but I can’t populate the table width attribute with my php variable holding the value of 850. The line snippet shown here creates the table ok:

[code=php]<TABLE ID=”table_width” border=0 width=”<?php echo $php_width?>”>[/code]

The JS code below would normally populate the table width with no problems:

[code=php]var table_width = ‘<?php echo $php_width?>’;
document.getElementById(‘table_width’).width = table_width;[/code]

HOWEVER, what I have determined is that since the table structure never existed before (when the form first loaded), the getElementById(‘table_width’).width statement doesn’t work.

If the table structure existed on the form when first loaded then of course it would work and set the table width.

So, this ajax problem is different from all of my other ajax coding because here I am trying to “ajax” a new table onto an existing form that was never there before AND then set its table width attribute. The table structure comes into the form fine but I can’t access it’s .width attribute using my php variables.

Does anyone know the fix for this?

Thanks…

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@scragarJan 20.2008 — ID's cannot have the _ character, it makes them invalid.

either way I don't see why you can't put the width in the table when it's being served?
Copy linkTweet thisAlerts:
@rfreshauthorJan 20.2008 — That was it! Thanks...
Copy linkTweet thisAlerts:
@scragarJan 20.2008 — sorry, but I can't say much more without seeing more.

you could(although I doubt it will be perfect) try:
[code=php]
blah.innerHTML = MyAjaxText;
if(document.getElementById('table_width'))
document.getElementById('table_width').style.width = "850px";[/code]

however it's untested.
×

Success!

Help @rfresh spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...